package com.sky.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;

/**
 * Redis配置类
 * 如果不创建 框架会自己创建，这里只是配置一下
 */
@Configuration
@Slf4j
public class RedisConfiguration extends CachingConfigurerSupport {
    @Bean
    public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory connectionFactory) {
        RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
        // 默认是redis  Key的序列化器
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        //设置redis的连接工厂对象
        redisTemplate.setConnectionFactory(connectionFactory);

        return redisTemplate;
    }
}
